package com.ptp.chat;

import java.util.Map;

import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * 
 * @author nnli
 *
 */
public interface IChat {

	default void send(String userId,String receiveId, Map<String, Channel> channels,String message) {
		Channel channel = channels.get(receiveId);
		//对方不在线,进行数据持久化,推送一条消息到服务端 TODO
		if(channel == null){
			channel = channels.get(userId);
			channel.writeAndFlush(new TextWebSocketFrame("对方不在线,消息有延迟"));
		}else{
			channel.writeAndFlush(new TextWebSocketFrame(message));
			channel = channels.get(userId);
			channel.writeAndFlush(new TextWebSocketFrame("消息发送成功"));
		}

	}
	
	default void send(String userId,String[] receiveId, Map<String, Channel> channels,String message) {
		for (String rId : receiveId) {
			Channel channel = channels.get(rId);
			channel.writeAndFlush(new TextWebSocketFrame(message));
		}
		Channel channel = channels.get(userId);
		channel.writeAndFlush(new TextWebSocketFrame("消息发送成功"));
	}
}
